﻿using System;
using System.Collections;
using System.Linq;
using System.Text;

namespace TMHuy.config
{
    [System.Xml.Serialization.XmlInclude(typeof(Zone))]
    [System.Xml.Serialization.XmlInclude(typeof(Troop))]
    [System.Xml.Serialization.XmlInclude(typeof(Building))]
    [System.Xml.Serialization.XmlInclude(typeof(BuyTroop))]
    public class Village
    {
        public string name;
        public string id;
        public int x;
        public int y;
        public int current;
        public long lastSent;
        public ArrayList zones = new ArrayList();
        public ArrayList troops = new ArrayList();
        public ArrayList buildingQueues = new ArrayList();
        public ArrayList troopToBuy = new ArrayList();
        public ArrayList scoutTargets = new ArrayList();
        public bool autoUpRes;
        public bool autoParty = false;
        public int currentScout = 0;

        public Building getFirstAny()
        {
            if (buildingQueues.Count > 0)
            {
                return (Building)buildingQueues[0];
            }
            return null;
        }

        public Building getFirstBuilding()
        {
            foreach (Building building in buildingQueues)
            {
                if (!building.resField) return building;
            }
            return null;
        }

        public Building getFirstResField()
        {
            foreach (Building building in buildingQueues)
            {
                if (building.resField) return building;
            }
            return null;
        }

        public int getQueuedLevel(string link, int current)
        {
            int level = current;
            foreach (Building building in buildingQueues)
            {
                if (building.buildLink.Equals(link) && building.level > level)
                {
                    level = building.level;
                }
            }
            return level;
        }

        public string getXY()
        {
            return x.ToString() + "," + y.ToString();
        }

        public void resetDefend()
        {
            for (int i = 0; i < zones.Count; i++)
            {
                Zone zone = (Zone)zones[i];
                zone.defend = int.MaxValue;
            }
        }

        public int getNCleanOasis()
        {
            int count = 0;
            foreach (Zone zone in zones)
            {
                if (zone.defend == 0 || zone.defend == int.MaxValue) count++;
            }
            return count;
        }
    }

}
